﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;


public partial class AdminX_Product_ProductTradeMarkMain : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
          
        //Alert1.HideMessage();
        if (!IsPostBack)
        {
            SetLableLang();
            //ShowMess();
            BindDataToGrid(1);
        }
    }

    private void SetLableLang()
    {
        int nDefaultLang = Support.GetDefaultLanguage();
        btnAddnew.Text = MultipleLanguage.BTN_ADDNEW[nDefaultLang-1];
        
    }
    //private void ShowMess()
    //{
    //    int nDefaultLanguage = Support.GetDefaultLanguage();
    //    int nMessage = ConvertData.ConvertToInt(Request.QueryString[Config.MESS_ID]);
    //    lblWarning.Text = MessagesAlert.SEARCH_NO_ITEM[nDefaultLanguage];
    //    switch (nMessage)
    //    {
    //        case 1:
    //            Alert1.ShowMessage(1, MessagesAlert.INSERT_SUCCESSFULL[nDefaultLanguage]);
    //            break;
    //        case 2:
    //            Alert1.ShowMessage(1, MessagesAlert.UPDATE_SUCCESSFUL[nDefaultLanguage]);
    //            break;
    //        default:
    //            Alert1.HideMessage();
    //            break;

    //    }
    //}
    private void BindDataToGrid(int CurrentPageIndex)
    {
        ProductTradeMark obj = new ProductTradeMark();
        DataTable dtb = new DataTable();
        int nPageCount = 0;
        dtb = obj.Search();
        RpProductTradeMark.DataSource = dtb;
        RpProductTradeMark.DataBind();
        int nDefaultLanguage = Support.GetDefaultLanguage();
        lblTotalRecord.Text = MultipleLanguage.LBL_TOTAL_ITEM[nDefaultLanguage - 1] + nPageCount + MultipleLanguage.LBL_FOUND[nDefaultLanguage - 1];
        nPageCount = dtb.Rows.Count;
        
    }

    protected void RpLink_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);
        ProductTradeMark obj = new ProductTradeMark();
        switch (strCommand)
        {
            case "Delete":
                int nDelete = obj.DeleteById(nID);
                //if (nDelete > 0)
                //    Alert1.ShowMessage(1, MessagesAlert.DELETE_SUCCESSFULL[nDefaultLanguage]);
                //else
                //    Alert1.ShowMessage(2, MessagesAlert.DELETE_UNSUCCESSFULL[nDefaultLanguage]);
                BindDataToGrid(1);
                break;

            case "Edit":
                string sEdit = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TRADEMARK_ADD + "&" + Config.ACTION + "=" + Config.ACTION_EDIT + "&" + Config.ACTION_ID + "=" + nID;
                Response.Redirect(sEdit);
                break;
        }
    }
    protected void RpLink_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblProductTradeMark = (Label)e.Item.FindControl("lblTradeMark");
            Image imgProductTradeMarkLogo = (Image)e.Item.FindControl("imgTradeMarkLogo");
            LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");
            LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");

            lblProductTradeMark.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TradeMarkName"));
            string sImage = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TradeMarkImage"));
            imgProductTradeMarkLogo.ImageUrl = Config.ROOT + Config.IMAGE_TRADEMARK_DEFAULT_UPLOAD + sImage;

            lnkEdit.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductTradeMarkID"));
            lnkDelete.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.DELETE_ALERT[nDefaultLanguage]);
            lnkDelete.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ProductTradeMarkID"));
        }
    }
    protected void btnAddnew_Click1(object sender, EventArgs e)
    {
        string sAddNew = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_TRADEMARK_ADD + "&" + Config.ACTION + "=" + Config.ACTION_ADD;
        Response.Redirect(sAddNew);
    }
}